#define MYNAME "gdb"
-#define GDB_VER_1 1
-#define GDB_VER_2 2
-#define GDB_VER_3 3
-
-#define GDB_VER_UTF8 GDB_VER_3
-#define GDB_VER_MIN GDB_VER_1
-#define GDB_VER_MAX GDB_VER_3
-
#define GDB_DEF_CLASS gt_waypt_class_user_waypoint
#define GDB_DEF_HIDDEN_CLASS gt_waypt_class_map_point
-#define GDB_DEF_ICON 18
-
-#define GDB_NAME_BUFFERLEN 1024
#define GDB_DBG_WPT 1
#define GDB_DBG_RTE 2
#undef GDB_DEBUG
// #define GDB_DEBUG 0xff
-#define DBG(a,b) if ((GDB_DEBUG & (a)) && (b))
-
-#define NOT_EMPTY(a) (a && *a)
+#define DBG(a, b) if ((GDB_DEBUG & (a)) && (b))
void
GdbFormat::gdb_flush_waypt_queue(QList<Waypoint*>* Q)
/*-----------------------------------------------------------------------------*/
#define FREAD_C gbfgetc(fin)
-#define FREAD(a,b) gbfread(a,(b),1,fin)
+#define FREAD(a, b) gbfread(a, (b), 1, fin)
#define FREAD_i32 gbfgetint32(fin)
#define FREAD_i16 gbfgetint16(fin)
#define FREAD_DBL gbfgetdbl(fin)
{
QString rv;
char* s = gdb_fread_cstr(fin);
- if (gdb_ver >= GDB_VER_UTF8) {
+ if (gdb_ver >= kGDBVerUTF8) {
rv = QString::fromUtf8(s);
} else {
rv = QString::fromLatin1(s);
if (fabs(dist) > 100) {
fatal(MYNAME ": Route point mismatch!\n" \
- " \"%s\" from waypoints differs to \"%s\"\n" \
- " from route table by more than %0.1f meters!\n", \
+ " \"%s\" from waypoints differs to \"%s\"\n" \
+ " from route table by more than %0.1f meters!\n", \
qPrintable(tmp->shortname), qPrintable(ref->shortname), dist);
}
}
/*******************************************************************************/
/* TOOLS AND MACROS FOR THE WRITER */
/*-----------------------------------------------------------------------------*/
-void GdbFormat::FWRITE_CSTR(const QString& a) const
+void GdbFormat::gdb_write_cstr(QStringView a) const
{
if (a.isEmpty()) {
gbfputc(0, fout);
return;
}
- if (gdb_ver >= GDB_VER_UTF8) {
+ if (gdb_ver >= kGDBVerUTF8) {
gbfputcstr(a.toUtf8().constData(), fout);
} else {
gbfputcstr(a.toLatin1().constData(), fout);
}
}
-#define FWRITE_i16(a) gbfputint16((a),fout)
-#define FWRITE_i32(a) gbfputint32((a),fout)
-#define FWRITE(a, b) gbfwrite(a,(b),1,fout)
-#define FWRITE_C(a) gbfputc((a),fout)
-#define FWRITE_DBL(a,b) gdb_write_dbl((a),(b))
+#define FWRITE_i16(a) gbfputint16((a), fout)
+#define FWRITE_i32(a) gbfputint32((a), fout)
+#define FWRITE(a, b) gbfwrite(a, (b), 1, fout)
+#define FWRITE_C(a) gbfputc((a), fout)
+#define FWRITE_DBL(a, b) gdb_write_dbl((a), (b))
#define FWRITE_TIME(a) gdb_write_time((a))
-#define FWRITE_CSTR_LIST(a) gdb_write_cstr_list((a))
-#define FWRITE_LATLON(a) gbfputint32(GPS_Math_Deg_To_Semi((a)),fout)
+#define FWRITE_LATLON(a) gbfputint32(GPS_Math_Deg_To_Semi((a)), fout)
void
-GdbFormat::gdb_write_cstr_list(const char* str) const
+GdbFormat::gdb_write_cstr_list(QStringView str) const
{
- if NOT_EMPTY(str) {
+ if (!str.isEmpty()) {
gbfputint32(1, fout);
- gbfputcstr(str, fout);
+ gdb_write_cstr(str);
} else {
gbfputint32(0, fout);
}
}
-void
-GdbFormat::gdb_write_cstr_list(const QString& str) const
-{
- gdb_write_cstr_list(CSTRc(str));
-}
-
void
GdbFormat::gdb_write_dbl(const double value, const double def) const
{
}
gdb_ver = drec.at(1) - 'k' + 1;
- if ((gdb_ver < GDB_VER_MIN) || (gdb_ver > GDB_VER_MAX)) {
+ if ((gdb_ver < kGDBVerMin) || (gdb_ver > kGDBVerMax)) {
fatal(MYNAME ": Unknown or/and unsupported GDB version (%d.0)!", gdb_ver);
}
/* VERSION DEPENDENT CODE */
- if (gdb_ver <= GDB_VER_2) {
+ if (gdb_ver <= kGDBVer2) {
FREAD(buf, 2); /* ?????????????????????????????????? */
waypt_flag = FREAD_C;
if (wpt_class != 0) {
res->description = l.url_;
}
- } else { // if (gdb_ver >= GDB_VER_3)
+ } else { // if (gdb_ver >= kGDBVer3)
waypt_flag = 0;
}
/* VERSION DEPENDENT CODE */
- if (gdb_ver <= GDB_VER_2) {
+ if (gdb_ver <= kGDBVer2) {
if (waypt_flag != 0) {
FREAD(buf, 1);
}
}
/* VERSION DEPENDENT CODE */
- if (gdb_ver >= GDB_VER_3) {
+ if (gdb_ver >= kGDBVer3) {
if (FREAD_i32 == 1) {
garmin_fs_t::set_phone_nr(gmsd, fread_cstr());
(void) FREAD_STR(); /* ?? fax / mobile ?? */
res->icon_descr = gt_find_desc_from_icon_number(icon, GDB);
#if GDB_DEBUG
- DBG(GDB_DBG_WPTe, icon != GDB_DEF_ICON)
+ DBG(GDB_DBG_WPTe, icon != kGDBDefIcon)
printf(MYNAME "-wpt \"%s\" (%d): icon = \"%s\" (MapSource symbol %d)\n",
qPrintable(res->shortname), wpt_class, qPrintable(res->icon_descr), icon);
#endif
if (FREAD_C != 0) {
FREAD(buf, 8); /* aviation data (?); only seen with class "1" (Airport) */
/* VERSION DEPENDENT CODE */
- if (gdb_ver >= GDB_VER_3) {
+ if (gdb_ver >= kGDBVer3) {
FREAD(buf, 8); /* a second block since V3 */
}
}
}
/* VERSION DEPENDENT CODE */
- if (gdb_ver >= GDB_VER_2) {
+ if (gdb_ver >= kGDBVer2) {
FREAD(buf, 8);
- if (gdb_ver >= GDB_VER_3) {
+ if (gdb_ver >= kGDBVer3) {
FREAD(buf, 2);
}
}
} /* ENDFOR: for (i = 0; i < points; i++) */
/* VERSION DEPENDENT CODE */
- if (gdb_ver <= GDB_VER_2) {
+ if (gdb_ver <= kGDBVer2) {
rte->rte_urls.AddUrlLink(UrlLink(fread_cstr()));
} else {
rte->rte_urls.AddUrlLink(UrlLink(gdb_fread_strlist()));
}
/* VERSION DEPENDENT CODE */
- if (gdb_ver >= GDB_VER_3) {
+ if (gdb_ver >= kGDBVer3) {
res->rte_urls.AddUrlLink(UrlLink(gdb_fread_strlist()));
- } else { /* if (gdb_ver <= GDB_VER_2) */
+ } else { /* if (gdb_ver <= kGDBVer2) */
res->rte_urls.AddUrlLink(UrlLink(FREAD_CSTR_AS_QSTR));
}
#if GDB_DEBUG
short_h = mkshort_new_handle();
- setshort_length(short_h, GDB_NAME_BUFFERLEN);
+ setshort_length(short_h, kGDBNameBufferLen);
setshort_badchars(short_h, "\r\n\t");
setshort_mustupper(short_h, 0);
setshort_mustuniq(short_h, 1);
int len, n = 0;
struct tm tm;
- FWRITE_CSTR("MsRcf");
- FWRITE_i32(2);
+ FWRITE("MsRc", 4); // Signature
+ FWRITE_i16(0x66); // Primary File Format
- strncpy(buff, "Dx", sizeof(buff));
- buff[1] = 'k' - 1 + gdb_ver;
- FWRITE_CSTR(buff);
+ FWRITE_i32(2); // Record Length in Bytes
+ FWRITE_C('D'); // Record Type
+ FWRITE_i16(gdb_ver + 0x6a); // File Format
#if 0
/* Take this if anything is wrong with our self generated watermark */
FWRITE_i32(len);
FWRITE(buff, len + 1);
- FWRITE_CSTR("MapSource"); /* MapSource magic */
+ gdb_write_cstr(u"MapSource"); /* MapSource magic */
}
/*-----------------------------------------------------------------------------*/
int wpt_class = wpt->wpt_flags.fmt_use; /* trick */
- FWRITE_CSTR(shortname); /* unique (!!!) shortname */
+ gdb_write_cstr(shortname); /* unique (!!!) shortname */
FWRITE_i32(wpt_class); /* waypoint class */
- FWRITE_CSTR(garmin_fs_t::get_cc(gmsd, "")); /* country code */
+ gdb_write_cstr(garmin_fs_t::get_cc(gmsd, "")); /* country code */
if (wpt_class != 0) {
waypth_ct++;
FWRITE_LATLON(wpt->longitude); /* longitude */
FWRITE_DBL(wpt->altitude, unknown_alt); /* altitude */
if (!wpt->notes.isEmpty()) {
- FWRITE_CSTR(wpt->notes);
+ gdb_write_cstr(wpt->notes);
} else {
- FWRITE_CSTR(wpt->description);
+ gdb_write_cstr(wpt->description);
}
FWRITE_DBL(wpt->proximity_value_or(unknown_alt), unknown_alt); /* proximity */
FWRITE_i32(display); /* display */
FWRITE_i32(0); /* color */
FWRITE_i32(icon); /* icon */
- FWRITE_CSTR(garmin_fs_t::get_city(gmsd, "")); /* city */
- FWRITE_CSTR(garmin_fs_t::get_state(gmsd, "")); /* state */
- FWRITE_CSTR(garmin_fs_t::get_facility(gmsd, "")); /* facility */
+ gdb_write_cstr(garmin_fs_t::get_city(gmsd, "")); /* city */
+ gdb_write_cstr(garmin_fs_t::get_state(gmsd, "")); /* state */
+ gdb_write_cstr(garmin_fs_t::get_facility(gmsd, "")); /* facility */
FWRITE_C(0); /* unknown */
FWRITE_DBL(wpt->depth_value_or(unknown_alt), unknown_alt); /* depth */
/* VERSION DEPENDENT CODE */
- if (gdb_ver <= GDB_VER_2) {
+ if (gdb_ver <= kGDBVer2) {
FWRITE(zbuf, 3);
FWRITE(zbuf, 4);
QString ld;
descr == CSTRc(wpt->shortname)) {
descr.clear();
}
- FWRITE_CSTR(descr);
- } else { /* if (gdb_ver > GDB_VER_3) */
+ gdb_write_cstr(descr);
+ } else { /* if (gdb_ver > kGDBVer3) */
// url_link* url_next;
// const char* str;
QString str;
} else {
str = "";
}
- FWRITE_CSTR(str);
+ gdb_write_cstr(str);
FWRITE(zbuf, 5); /* instruction dependent */
/* GBD doesn't have a native description field */
if (str == wpt->notes) {
d.clear();
}
- FWRITE_CSTR(d); /* instruction */
+ gdb_write_cstr(d); /* instruction */
#else
str = wpt->description;
if (str && (strcmp(str, wpt->shortname) == 0)) {
if (str && wpt->notes && (strcmp(str, wpt->notes) == 0)) {
str = NULL;
}
- FWRITE_CSTR(str); /* instruction */
+ gdb_write_cstr(str); /* instruction */
#endif
FWRITE_i32(wpt->urls.size());
foreach (UrlLink l, wpt->urls) {
- FWRITE_CSTR(l.url_);
+ gdb_write_cstr(l.url_);
}
}
FWRITE_TIME(wpt->GetCreationTime().toTime_t());
/* VERSION DEPENDENT CODE */
- if (gdb_ver >= GDB_VER_3) {
+ if (gdb_ver >= kGDBVer3) {
QString str = garmin_fs_t::get_phone_nr(gmsd, "");
if (!str.isEmpty()) {
FWRITE_i32(1);
- FWRITE_CSTR(str);
- FWRITE_CSTR("");
+ gdb_write_cstr(str);
+ gdb_write_cstr();
} else {
FWRITE_i32(0);
}
- FWRITE_CSTR(garmin_fs_t::get_country(gmsd, ""));
- FWRITE_CSTR(garmin_fs_t::get_postal_code(gmsd, ""));
+ gdb_write_cstr(garmin_fs_t::get_country(gmsd, ""));
+ gdb_write_cstr(garmin_fs_t::get_postal_code(gmsd, ""));
}
}
memset(zbuf, 0, sizeof(zbuf));
memset(ffbuf, 0xFF, sizeof(ffbuf));
- FWRITE_CSTR(rte_name);
+ gdb_write_cstr(rte_name);
FWRITE_C(0); /* display/autoname - 1 byte */
route_compute_bounds(rte, &bounds);
garmin_fs_t* gmsd = garmin_fs_t::find(wpt);
/* extra_data may contain a modified shortname */
- FWRITE_CSTR((wpt->extra_data) ? *static_cast<QString*>(wpt->extra_data) : wpt->shortname);
+ gdb_write_cstr((wpt->extra_data) ? *static_cast<QString*>(wpt->extra_data) : wpt->shortname);
int wpt_class = wpt->wpt_flags.fmt_use; /* trick */
FWRITE_i32(wpt_class); /* waypoint class */
- FWRITE_CSTR(garmin_fs_t::get_cc(gmsd, "")); /* country */
+ gdb_write_cstr(garmin_fs_t::get_cc(gmsd, "")); /* country */
#ifdef GMSD_EXPERIMENTAL
if (gmsd && gmsd->flags.subclass && (wpt_class >= gt_waypt_class_map_point)) {
FWRITE(gmsd->subclass, sizeof(gmsd->subclass));
}
/* VERSION DEPENDENT CODE */
- if (gdb_ver >= GDB_VER_2) {
+ if (gdb_ver >= kGDBVer2) {
FWRITE(ffbuf, 8);
- if (gdb_ver >= GDB_VER_3) {
+ if (gdb_ver >= kGDBVer3) {
FWRITE(zbuf, 2);
}
}
}
/* VERSION DEPENDENT CODE */
- if (gdb_ver <= GDB_VER_2) {
+ if (gdb_ver <= kGDBVer2) {
if (rte->rte_urls.HasUrlLink()) {
- FWRITE_CSTR(rte->rte_urls.GetUrlLink().url_);
+ gdb_write_cstr(rte->rte_urls.GetUrlLink().url_);
} else {
- FWRITE_CSTR("");
+ gdb_write_cstr();
}
- } else { /* if (gdb_ver >= GDB_VER_3) */
+ } else { /* if (gdb_ver >= kGDBVer3) */
if (rte->rte_urls.HasUrlLink()) {
- FWRITE_CSTR_LIST(rte->rte_urls.GetUrlLink().url_);
+ gdb_write_cstr_list(rte->rte_urls.GetUrlLink().url_);
} else {
- FWRITE_CSTR_LIST("");
+ gdb_write_cstr_list();
}
/* "Magenta" (14) is MapSource default */
FWRITE_i32((rte->line_color.bbggrr < 0) ? 14 : gt_color_index_by_rgb(rte->line_color.bbggrr));
FWRITE_C(0);
- FWRITE_CSTR(rte->rte_desc);
+ gdb_write_cstr(rte->rte_desc);
}
}
{
int points = trk->rte_waypt_ct();
- FWRITE_CSTR(trk_name);
+ gdb_write_cstr(trk_name);
FWRITE_C(0);
/* "Unknown" (0) is MapSource default */
FWRITE_i32(gt_color_index_by_rgb(trk->line_color.bbggrr));
/* finalize track */
/* VERSION DEPENDENT CODE */
- if (gdb_ver <= GDB_VER_2) {
+ if (gdb_ver <= kGDBVer2) {
if (trk->rte_urls.HasUrlLink()) {
- FWRITE_CSTR(trk->rte_urls.GetUrlLink().url_);
+ gdb_write_cstr(trk->rte_urls.GetUrlLink().url_);
} else {
- FWRITE_CSTR("");
+ gdb_write_cstr();
}
- } else { /* if (gdb_ver >= GDB_VER_3 */
+ } else { /* if (gdb_ver >= kGDBVer3 */
if (trk->rte_urls.HasUrlLink()) {
- FWRITE_CSTR_LIST(trk->rte_urls.GetUrlLink().url_);
+ gdb_write_cstr_list(trk->rte_urls.GetUrlLink().url_);
} else {
- FWRITE_CSTR_LIST("");
+ gdb_write_cstr_list();
}
}
}
int icon = garmin_fs_t::get_icon(gmsd, -1);
if (icon < 0) {
if (wpt->icon_descr.isNull()) {
- icon = GDB_DEF_ICON;
+ icon = kGDBDefIcon;
} else {
icon = gt_find_icon_number_from_desc(wpt->icon_descr, GDB);
}
track_disp_all(write_track_cb_lambda, nullptr, nullptr);
FWRITE_i32(2); /* finalize gdb with empty map segment */
- FWRITE_CSTR("V");
+ gdb_write_cstr(u"V");
FWRITE_C(1);
}